#pragma once 

#include <string>
#include <hash_map>
#include <iostream>

#include "..\Raknet\RakPeerInterface.h"

using namespace RakNet;
using std::string;

namespace Network
{
	namespace Peer
	{
		class Neighbour
		{
		public:
			SystemAddress address;
			RakNet::RakNetGUID guid;
			int lastConnection;

			Neighbour()
			{
				address = SystemAddress();
				guid = RakNet::RakNetGUID();
				lastConnection = 0;
			}

			Neighbour(SystemAddress& _address, RakNetGUID _guid)
			{
				address = _address;
				guid = _guid;
				lastConnection = 0;
			}

			Neighbour(SystemAddress _address, RakNetGUID _guid, int _logicalTime)
			{
				address = _address;
				guid = _guid;
				lastConnection = _logicalTime;
			}

			Neighbour(string p_neighbourDetails)
			{
				FromString(p_neighbourDetails);
			}

			Neighbour(const Neighbour& p_neighbour)
			{
				address = p_neighbour.address;
				guid = p_neighbour.guid;
				lastConnection = p_neighbour.lastConnection;
			}

			void UpdateLogicalTime(int time)
			{
				lastConnection = time;
			}

			std::string ToString()
			{
				return std::string(guid.ToString()) + "-" + std::string(address.ToString()) + "-" + std::to_string(lastConnection);
			}
			void FromString(std::string p_data)
			{
				std::string data[3];
				HelperClass::ParseStringSentence(p_data, "-", data);

				guid.FromString(data[0].c_str());
				address.FromString(data[1].c_str());
				lastConnection = stoi(data[2]);
			}

			bool operator < (const Neighbour& neighbour)
			{
				return lastConnection < neighbour.lastConnection;
			}

			bool operator >(const Neighbour& neighbour)
			{
				return lastConnection > neighbour.lastConnection;
			}

			bool SortFunction(const Neighbour lhs, const Neighbour rhs)
			{
				return lhs.lastConnection > rhs.lastConnection;
			}

			bool operator == (const Neighbour& rhs) const
			{
				return address == rhs.address;
				//return lastConnection == rhs.lastConnection;
				return true;
			}

			Neighbour& operator = (const Neighbour& p_neighbour)
			{
				address = p_neighbour.address;
				guid = p_neighbour.guid;
				lastConnection = p_neighbour.lastConnection;
				return *this;
			}
		};

		
		
	}
}


